package com.demo.store.serivce.remote.impl;

import com.demo.common.base.constant.SysConstant;
import com.demo.common.base.pojo.JsonRes;
import com.demo.store.serivce.remote.DispatchRemoteUserMainService;
import com.demo.user.bo.CreateUserBO;
import com.demo.user.bo.UserMainPageBO;
import com.demo.user.exception.DemoUserException;
import com.demo.user.remote.RemoteUserMainService;
import com.demo.user.vo.UserMainVO;
import com.mybatisflex.core.paginate.Page;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Objects;

/**
 * 调用RemoteUserMainServiceImpl实现
 *
 * @author DayDayUp
 * create on 2023-05-18
 **/
@Service
public class DispatchRemoteUserMainServiceImpl implements DispatchRemoteUserMainService {
    @Resource
    private RemoteUserMainService remoteUserMainService;

    /**
     * 分页获取用户信息
     * @param userMainPageBO 查询参数
     * @return Page<UserMainVO>
     */
    @Override
    public Page<UserMainVO> pageUserMain(UserMainPageBO userMainPageBO){
        JsonRes<Page<UserMainVO>> jsonRes = remoteUserMainService.pageUserMain(userMainPageBO);
        if (Objects.isNull(jsonRes) || !Objects.equals(SysConstant.SUCCESS, jsonRes.getStatus()) || Objects.isNull(jsonRes.getData()) ) {
            return null;
        }
        return jsonRes.getData();
    }

    /**
     * 创建用户
     * @param createUserBO 参数
     */
    @Override
    public void createUser(CreateUserBO createUserBO){
        JsonRes<Void> jsonRes = remoteUserMainService.createUser(createUserBO);
        if (Objects.isNull(jsonRes) || !Objects.equals(SysConstant.SUCCESS, jsonRes.getStatus())) {
            throw new DemoUserException("创建用户失败");
        }
    }

    /**
     * 创建用户
     * @param createUserBO 参数
     */
    @Override
    public void createUser1(CreateUserBO createUserBO){
        JsonRes<Void> jsonRes = remoteUserMainService.createUser1(createUserBO);
        if (Objects.isNull(jsonRes) || !Objects.equals(SysConstant.SUCCESS, jsonRes.getStatus())) {
            throw new DemoUserException("创建用户失败1");
        }
    }
}
